package com.zfk.transaction.util;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.StandardCharsets;

/**
 * @description: Base64
 * @author: dong.huanan
 * @create: 2021-01-12
 **/
public class Base64Utils {

    /**
     * Base64编码
     *
     * @param text
     * @return
     */
    public static String encode(String text) {
        Base64 base64 = new Base64();
        byte[] textByte = text.getBytes(StandardCharsets.UTF_8);
        return base64.encodeToString(textByte);
    }

    /**
     * Base64解码
     *
     * @param encodedText
     * @return
     */
    public static String decode(String encodedText) {
        Base64 base64 = new Base64();
        return new String(base64.decode(encodedText), StandardCharsets.UTF_8);
    }
}
